package com.house.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.house.common.Result;
import com.house.entity.*;
import com.house.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 用户
 */
@Controller
@RequestMapping("user")
public class UserController {



    @Autowired
    UserService userService;


    /**
     * 用户管理页
     * @return
     */
    @GetMapping("manage")
    public String manage() {

        return "admin/userManage";
    }

    @PostMapping("manage/list")
    @ResponseBody
    public List<User> list(User user){
        return userService.list(Wrappers.<User>query().orderByDesc("create_time"));
    }


    /**
     * 删除用户
     * @param id
     * @return
     */
    @PostMapping("/manage/delete")
    @ResponseBody
    public Result delete(@RequestBody List<String> id){
        if(id.contains("admin")) {
            return Result.error("禁止删除admin用户！");
        }
        userService.removeByIds(id);
        return Result.ok();
    }
}
